//package com.kun.util;
//
//import com.kun.config.MinIoAutoConfig;
//import com.kun.config.properties.MinIoProperties;
//import io.minio.*;
//import io.minio.http.Method;
//import io.minio.messages.Bucket;
//import io.minio.messages.Item;
//import lombok.extern.slf4j.Slf4j;
//
//import java.io.ByteArrayInputStream;
//import java.io.InputStream;
//import java.util.List;
//import java.util.concurrent.TimeUnit;
//
///**
// * @author kun.li
// */
//@Slf4j
//public class MinIoUtil {
//
//    private final MinioClient minioClient;
//
//    private final MinIoProperties minIoProperties;
//
//    public MinIoUtil(MinioClient minioClient, MinIoProperties minIoProperties) {
//        this.minioClient = minioClient;
//        this.minIoProperties = minIoProperties;
//    }
//
//    public boolean bucketExists(String bucketName) throws Exception {
//        return minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
//    }
//
//    public void makeBucket(String bucketName) throws Exception {
//        minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
//    }
//
//    public String uploadObject(String buckName, String fileName, String filePath) throws Exception {
//        ObjectWriteResponse objectWriteResponse = minioClient.uploadObject(
//                UploadObjectArgs.builder()
//                        .bucket(buckName)
//                        .object(fileName)
//                        .filename(filePath)
//                        .build());
//        return objectWriteResponse.object();
//    }
//
//    public ObjectWriteResponse createBucketFolder(String folderName) throws Exception {
//        return createBucketFolder(minIoProperties.getBuckName(), folderName);
//    }
//
//    public ObjectWriteResponse createBucketFolder(String buckName, String folderName) throws Exception {
//        String object = folderName;
//        if (!object.equals("/")) {
//            object = folderName + "/";
//        }
//        return minioClient.putObject(PutObjectArgs.builder()
//                .bucket(buckName)
//                .object(object)
//                .stream(new ByteArrayInputStream(new byte[0]), 0, 0)
//                .build());
//    }
//
//    public void removeObject(String objectName) throws Exception {
//        removeObject(minIoProperties.getBuckName(), objectName);
//    }
//
//    public void removeObject(String buckName, String objectName) throws Exception {
//        minioClient.removeObject(RemoveObjectArgs.builder().bucket(buckName).object(objectName).build());
//    }
//
//    public void deleteBucket(String buckName) throws Exception {
//        minioClient.removeBucket(RemoveBucketArgs.builder().bucket(buckName).build());
//
//    }
//
//    public List<Bucket> getAllBucketInfo() throws Exception {
//        return minioClient.listBuckets();
//    }
//
//    public Iterable<Result<Item>> getBucketAllFile(String buckName, String folderName, Boolean isDeep) throws Exception {
//        return minioClient.listObjects(ListObjectsArgs.builder()
//                .bucket(buckName)
//                .prefix(folderName + "/")
//                .recursive(isDeep)
//                .build());
//
//    }
//
//    /**
//     * 共享给其他地址使用
//     *
//     * @param bucketName
//     * @param objectName
//     * @param expires
//     * @return
//     * @throws Exception
//     */
//    public String getFileUploadUrl(String bucketName, String objectName, int expires) throws Exception {
//        return minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
//                .bucket(bucketName)
//                .object(objectName)
//                .method(Method.GET)
//                .expiry(expires, TimeUnit.DAYS)
//                .build());
//    }
//
//    public ObjectWriteResponse fileUpload(String fileAbsolutePath, InputStream inputStream, long objectSize, String contentType) throws Exception {
//        return fileUpload(minIoProperties.getBuckName(), fileAbsolutePath, inputStream, objectSize, contentType);
//    }
//
//    public ObjectWriteResponse fileUpload(String buckName, String fileAbsolutePath, InputStream inputStream, long objectSize, String contentType) throws Exception {
//        return minioClient.putObject(PutObjectArgs.builder()
//                .bucket(buckName)
//                .object(fileAbsolutePath)
//                .stream(inputStream, objectSize, -1)
//                .contentType(contentType)
//                .build());
//    }
//
//    public GetObjectResponse getResponse(String object) throws Exception {
//        return getResponse(minIoProperties.getBuckName(), object);
//    }
//
//    public GetObjectResponse getResponse(String buckName, String object) throws Exception {
//        return minioClient.getObject(GetObjectArgs.builder()
//                .bucket(buckName)
//                .object(object)
//                .build());
//    }
//
//    public ObjectWriteResponse copyFile(String sourceObject, String targetObject) throws Exception {
//        return copyFile(minIoProperties.getBuckName(), sourceObject, minIoProperties.getBuckName(), targetObject);
//    }
//
//    public ObjectWriteResponse copyFile(String sourceObject, String targetBuckName, String targetObject) throws Exception {
//        return copyFile(minIoProperties.getBuckName(), sourceObject, targetBuckName, targetObject);
//    }
//
//    public ObjectWriteResponse copyFile(String sourceBuckName, String sourceObject, String targetBuckName, String targetObject) throws Exception {
//        return minioClient.copyObject(CopyObjectArgs.builder()
//                .source(CopySource.builder()
//                        .bucket(sourceBuckName)
//                        .object(sourceObject)
//                        .build())
//                .bucket(targetBuckName)
//                .object(targetObject)
//                .build());
//    }
//
//    public boolean checkBuckFileExist(String objectName) {
//        try {
//            return bucketExists(minIoProperties.getBuckName()) && minioClient.statObject(StatObjectArgs.builder().bucket(minIoProperties.getBuckName()).object(objectName).build()) != null;
//        } catch (Exception e) {
//            log.error("文件不存在", e);
//            return false;
//        }
//    }
//
//    public boolean checkBuckFileExist(String bucketName, String objectName) {
//        try {
//            return bucketExists(bucketName) && minioClient.statObject(StatObjectArgs.builder().bucket(bucketName).object(objectName).build()) != null;
//        } catch (Exception e) {
//            e.printStackTrace();
//            return false;
//        }
//    }
//
//    public String buildMinioAddress() {
//        return minIoProperties.getEndpoint() + "/" + minIoProperties.getBuckName();
//    }
//

//}
